package ui;

import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Printer {

	public JFrame window;
	public JTextArea text;
	private JScrollPane scrollPane;
	
	private int x, y;
	private int width, height;

	// for testing purposes only
	public Printer(  ) {
		window = new JFrame("CS6461 Computer Printer");
		text = new JTextArea( );
		
		this.x = 0;
		this.y = 0;
		this.width = 512;
		this.height = 512;
	}

	public Printer( int x, int y, int width, int height ) {
		window = new JFrame("CS6461 Computer Printer");
		text = new JTextArea( );
		
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
	
	public void show( ) {
		window.setLocation( x, y );
		window.setSize( width, height );
		
		Container content = window.getContentPane( );
		
		scrollPane = new JScrollPane(text); 
		scrollPane.createVerticalScrollBar();
		text.setEditable( false );
		
		content.add( scrollPane );
		//content.add( text );
		
		window.addWindowListener( new ExitListener( ) );
	    window.setVisible( true );
	}
	public void print( String s ) {
		String data = text.getText( ) + s;
		text.setText( data );
		text.setCaretPosition(text.getText().length() - 1);
	}
	public void print( char c ) {
		String data = text.getText( ) + c;
		text.setText( data );
		text.setCaretPosition(text.getText().length() - 1);
	}
	public void clear( ) {
		text.setText( "" );
	}
}
